package org.gd.hellojaxb.utils;

import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler;

import javax.xml.bind.Marshaller;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;

/**
 * @author Gorhover
 * @version 3.0
 */
@SuppressWarnings("unused")
public enum MarshallProperties {

    WITH_XML_HEADER(Marshaller.JAXB_FRAGMENT, false),
    WITHOUT_XML_HEADER(Marshaller.JAXB_FRAGMENT, true),
    FRAGMENT(Marshaller.JAXB_FRAGMENT, true),
    FORMATTED_OUTPUT(Marshaller.JAXB_FORMATTED_OUTPUT, true),
    NOT_FORMATTED_OUTPUT(Marshaller.JAXB_FORMATTED_OUTPUT, false),
    UTF8_ENCODING(Marshaller.JAXB_ENCODING, "UTF-8"),
    WINDOWS1251_ENCODING(Marshaller.JAXB_ENCODING, "windows-1251"),
    UNICODE_ENCODING(Marshaller.JAXB_ENCODING, "Unicode"),
    @Deprecated
    CDATA("com.sun.xml.internal.bind.characterEscapeHandler", new CharacterEscapeHandler() {
        @Override
        public void escape( char[] ac, int i, int j, boolean flag, Writer writer )
                throws IOException {
            System.out.println("ac: " + new String(ac));
            System.out.println("i: " + i);
            System.out.println("j: " + j);
            System.out.println("flag: " + flag);
            writer.write( ac, i, j );
        }
    });

    private String key;
    private Object value;

    private MarshallProperties(String key, Object value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public Object getValue() {
        return value;
    }
}
